﻿using System;
using System.Xml.Linq;
using System.Collections.Generic;

namespace EHR.Ctrls.QueryDesign
{
    public class FilterInfo : IXmlItem
    {
        public string FieldName { get; set; }
        public string DisplayName { get; set; }
        public string Value { get; set; }
        public FilterOp Op { get; set; }
        public bool IsAnd { get; set; }

        public XElement ToXml()
        {
            XElement el = new XElement("Filter",
                new XAttribute("FieldName", FieldName),
                new XAttribute("Value", Value),
                new XAttribute("Op", (int)Op),
                new XAttribute("IsAnd", IsAnd));

            return el;
        }

        public void FromXml(XElement el)
        {
            FieldName = el.Attribute("FieldName").Value;
            Value = el.Attribute("Value").Value;
            Op = (FilterOp)int.Parse(el.Attribute("Op").Value);
            string strIsAnd = el.Attribute("IsAnd").Value;
            IsAnd = bool.Parse(strIsAnd);
        }
    }

    public enum FilterOp
    {
        等于,
        不等于,
        大于,
        大于等于,
        小于,
        小于等于,
        始于,
        包含
    }

    public static class FilterOpHelper
    {
        private static IList<string> _AllOps;
        public static IList<string> AllOps
        {
            get
            {
                if (_AllOps == null)
                {
                    _AllOps = new List<string>
                    {
                        "=  等于",
                        "!= 不等于",
                        ">  大于",
                        ">= 大于等于",
                        "<  小于",
                        "<= 小于等于",
                        "{  始于",
                        "{} 包含"
                    };
                }
                return _AllOps;
            }
        }
    }
}
